<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/Sys/css/layui.css">
    <link rel="stylesheet" href="/Sys/css/sign.css">

    <link rel="stylesheet"
          href="/Sys/js/css/modules/layui-icon-extend/iconfont.css">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/Sys/css/font.css">
    <link rel="stylesheet" href="/Sys/css/xadmin.css">
    <script type="text/javascript"
            src="/Sys/js/jquery-3.3.1.min.js"></script>
    <script src="/Sys/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="/Sys/js/jquery.table2excel.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">


        <div class="layui-form-item">
            <label class="layui-form-label">选择年级：</label>
            <div class="layui-input-inline layui-form">
                <select lay-filter="grade">
                    <option value="2020">2020</option>
                    <option value="2021">2021</option>
                    <option value="2022">2022</option>
                </select>
            </div>

<!--            <label class="layui-form-label">选择班级：</label>-->
<!--            <div class="layui-input-inline layui-form">-->
<!--                <select lay-filter="cla">-->
<!--                    <option value="01">01</option>-->
<!--                    <option value="02">02</option>-->
<!--                    <option value="03">03</option>-->
<!--                </select>-->
<!--            </div>-->


            <label class="layui-form-label">选择科目：</label>
            <div class="layui-input-inline layui-form">
                <select lay-filter="coursename">
                    <option value="高数">高数</option>
                    <option value="java">java</option>
                    <option value="linux">linux</option>
                    <option value="javaWeb">javaWeb</option>
                    <option value="android">android</option>
                    <option value="数据结构">数据结构</option>
                    <option value="数据库">数据库</option>
                </select>
            </div>


            <div class="layui-form-item" style="margin-top: 10px">
                <!--                <label class="layui-form-label">选择类型：</label>-->
                <!--                <div class="layui-input-inline layui-form">-->
                <!--                    <select lay-filter="type">-->
                <!--                        <option value="未批改">未批改</option>-->
                <!--                        <option value="已批改">已批改</option>-->
                <!--                    </select>-->
                <!--                </div>-->


                                <button class="layui-btn" data-type="reload"><i class="layui-icon">&#xe615;</i></button>
            </div>

            <!--            <xblock>-->
            <!--                <button type="button" class="layui-btn layui-btn-primary" id="uploadExcel">批量导入</button>-->
            <!--                <button type="button" class="layui-btn layui-btn-primary" onclick="exportTable()">批量导出</button>-->
            <!--            </xblock>-->
            <table id="test" lay-filter="test"></table>
        </div>
</body>

<script type="text/html" id="barDemo">
    <a title="修改信息 " onclick="claCouModi()" href="javascript:;">
        <i class="layui-icon">&#xe642;</i>
    </a>
    <a title="删除" onclick="deleteScoreRecord()" href="javascript:;" lay-event="edit">
        <i class="layui-icon">&#xe640;</i>
    </a>
</script>


<script>

    function deleteScoreRecord(){
        layui.use('table',function(){
            var table = layui.table
            var checkStatus = table.checkStatus('csInfo');
            console.log(checkStatus)
            var num = checkStatus.data[0].stuno;
            var courseName = checkStatus.data[0].coursename;
            console.log(courseName)
            $.ajax({
                url:'deleteScoreRecord',
                data:{'num':num,"courseName":courseName},
                type:'post',
                success:function(data){
                    if(data=="success"){
                        parent.layer.msg('删除成功！', {icon: 1,time:2000,shade:0.2});
                        location.reload(true);
                    }else{
                        parent.layer.msg('删除失败！', {icon: 2,time:3000,shade:0.2});
                    }
                }
            });
        });
    }

    var documentWidth = $(document).width();
    layui.use(['table', 'form'], function () {
        var grade = "2020";
        var cla = "01";
        var coursename = "高数";
        var type = '已批改';
        var table = layui.table;
        var form = layui.form;
        form.render();
        form.on('select(grade)', function (data) {
            grade = data.value;
        })

        form.on('select(cla)', function (data) {
            cla = data.value;

        })

        form.on('select(coursename)', function (data) {
            coursename = data.value;
        })

        form.on('select(type)', function (data) {
            type = data.value;

        })

        table.render({
            elem: '#test'  //绑定table表格
            , id: 'csInfo'
            , method: 'post'
            , url: 'getGcs' //后台springmvc接收路径
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 3
                , limits: [3, 6, 9]
            }
            , cols: [
                [
                    {type: 'checkbox', width: documentWidth * 4 / 100}
                    , {field: 'stuno', title: '学号', width: documentWidth * 10 / 100, sort: true}
                    , {field: 'name', title: '姓名', width: documentWidth * 8 / 100, sort: true}
                    , {field: 'coursename', title: '学科', width: documentWidth * 8 / 100, sort: true}
                    , {field: 'score', edit: 'text', title: '成绩', width: documentWidth * 8 / 100, sort: true}
                    // , {field: 'type', edit: 'text', title: '类型', width: documentWidth * 8 / 100, sort: true}
                    , {field: 'operation', edit: 'text', title: '操作', toolbar: '#barDemo'}
                ]
            ]
            , where: {
                key: {
                    grade: grade,
                    cla: cla,
                    coursename: coursename,
                    type: type
                }
            }
        });


        var $ = layui.$, active = {

            reload: function () {
                table.reload('csInfo', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    url: 'getGcs'
                    , where: {
                        key: {
                            grade: grade,
                            cla: cla,
                            coursename: coursename,
                            type: type
                        }
                    }
                    , method: 'post'
                });
            }
        };


        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });


    function claCouModi() {
        var num = "";
        var coursename = "";
        layui.use('table', function () {
            var table = layui.table
            var checkStatus = table.checkStatus('csInfo');
            num = checkStatus.data[0].stuno;
            coursename = checkStatus.data[0].coursename;

        });
        layer.open({
            type: 2,
            title: '修改页面',
            skin: 'layui-layer-molv',
            shadeClose: false,
            shade: 0.8,
            area: ['700px', '450px'],
            content: 'claCouModi?num=' + num + "&coursename=" + coursename,
            end: function () {
                window.location.reload(); //刷新父页面
            }
        });
    }


</script>

</html>